#!/usr/bin/perl

use strict;
use WWW::NikePlus;
use Toolkit;

my $np = WWW::NikePlus->new(login => 'ufotofu@whistlinglemons.com',
                            password => 'uf0t0fu');

my @challenges = $np->get_challenge_list(lazy => 1);

my $chal;
foreach my $c (@challenges){
  $chal = $c if( $c->getID() == 610759998 );
}

quick($chal->getID(), $chal->getName());
$chal->getDetail();
my $members = $chal->getMembers();

my $total = 0;
my @table = (['Runner', 'Miles', 'Value']);
foreach my $who (@{$members}){
  my $name = $who->{'name'};
  my $mile = $who->{'progress'} * 0.621371192;
  $total += $mile;
  push(@table, [$name, $mile, sprintf('$%0.2f', $mile * .01)]);
  quick($name, $mile);
}

dump_table(table => \@table);
printf("Total Donation: \$%0.2f\n", $total * .01);
